/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
Ext.ns('refrigeratory');
Ext.menu.RangeMenu.prototype.icons = {
   gt: 'js/extensions/img/greater_then.png', 
   lt: 'js/extensions/img/less_then.png',
   eq: 'js/extensions/img/equals.png'
};
//Ext.grid.filter.StringFilter.prototype.icon = 'js/extensions/img/find.png';

refrigeratory.pn_viewlog_me = Ext.extend(Ext.Panel, {
	
    url: refrigeratory.REQUEST_URL

    ,initComponent:function() {
 
        // hard coded config (it cannot be changed while instantiating)
        // {{{
        var config = {        	
        	title: this.titleText
        	,id : 'pn_viewlog_me'
			,closable: true
    		,autoScroll: true
    		,style:"height:100%;"
    		,bodyStyle:"height:100%;"
			
        }; // eo config object
		     
        // apply config
        Ext.apply(this, Ext.apply(this.initialConfig, config));
        // }}}

 
        // call parent
        refrigeratory.pn_viewlog_me.superclass.initComponent.apply(this, arguments);
 
        // parent call post-processing, e.g. install event handlers
 
    } // eo function initComponent
	
	
    ,onRender:function() {
     
        // parent call pre-processing
 
        // call parent
        refrigeratory.pn_viewlog_me.superclass.onRender.apply(this, arguments);
 
        // parent call post-processing, e.g. install event handlers on rendered components
        this.add(this.createGp());
		this.doLayout();
        //this.doLayout();
 
    } // eo function onRender
    
    // 需本地化的文本
    ,titleText: '查看我的日志'
    // icon css class
    ,iconDelete: 'refrigeratory-icon-delete'
    ,iconAdd: 'refrigeratory-icon-add'
    ,iconSave: 'refrigeratory-icon-save'
		
	,createGp: function(){
		var store = new Ext.data.JsonStore({
    	url: this.url
		,method: 'POST'
		,baseParams: {
			action:'log'
			,operation: 'get'
			,type:'me'
			}
		,totalProperty: 'count'
		,root: 'data'
    		,fields:['logid','lname', 'uname','cname','time', 'description']
    		,autoLoad: false
    	});	
		store.load({params : {start:0,limit : 30}});
		
		var filters = new Ext.grid.GridFilters({
		  filters:[	  
			{type: 'numeric',  dataIndex: 'id'},
			{type: 'string',  dataIndex: 'cname'},
			{type: 'string',  dataIndex: 'uname'},
			{type: 'string',  dataIndex: 'lname'},
			{type: 'date',  dataIndex: 'time'}
			]
		});
		
		var pagingBar = new Ext.PagingToolbar({//分页工具栏
			store : store,
			pageSize :30,//每页显示的条数。用于系统自动计算它的start
			displayInfo : true,
			displayMsg :  '数据从第{0}条 - 第{1} 条 共 {2}条数据',
			emptyMsg : "没有记录",
			plugins: filters
        });
		store.on('beforeload', this.onJstGpBeforeLoad, this);
		store.on('load', this.onJstGpLoad, this);
			
		var cm = new Ext.grid.ColumnModel([
			{header: "级别", width: 150, sortable: true, dataIndex: 'lname'},
			{header: "类型", width: 150, sortable: true, dataIndex: 'cname'},
			{header: "时间", width: 150, sortable: true, dataIndex: 'time'},
			{header: "用户", width: 100, sortable: true, dataIndex: 'uname'},
			{header: "描述", width: 400, sortable: true, dataIndex: 'description'}
		]);
		
		var o = this.gp = new Ext.grid.GridPanel({
		ds: store,
		cm: cm,
		bbar: pagingBar,//分页引用，作为button。前面有定义,
		plugins: filters,
		title: '查看日志',
		autoHeight: true
		});		
      return o ;
	}  //fed
	
	//private
	,onJstGpBeforeLoad: function(){
    	this.getEl().mask("数据载入中...");
    }
	// private
    ,onJstGpLoad: function(store, records, options){
    	this.getEl().unmask();
    }
	
	//private 
	,createGpTbar: function(){
    	var tb = [];
    	this.btnRefresh = new Ext.Toolbar.Button({
    		text: "刷新"
    		,handler: this.onBtnRefreshClick.createDelegate(this)
    	});
    	tb.push(this.btnRefresh);
    	return tb;
    }
	//private 
	,onBtnRefreshClick: function(){
    	this.reloadGp();
    }
	
	,reloadGp: function(){
        this.gp.store.reload({
        	params:{
    			action:'receivemsg',
    			operation: 'get_receivemsg'
        	}
		})
	}
	
	,onJstListLoad: function(store, records, options){
    	this.gp.getStore().load();
    }
    
	
}); // eo extend
// register xtype
Ext.reg('pn_viewlog_me', refrigeratory.pn_viewlog_me);